import java.util.List;

public class MyQueue {
    static class ListNode{
        private int val;
        private ListNode prev;
        private ListNode next;

        public ListNode(int val){
            this.val=val;
        }

    }

    private ListNode front;//对头
    private ListNode rear;//队尾

    private int usedSize;
    public void offer(int data){
        ListNode node=new ListNode(data);
    if(front==null){
            front=rear=node;
    } else {
        node.next = front;
        front.prev = node;
        front = node;
    }
        usedSize++;
    }
    public int pool(){

        if(front==null){
            return -1;//此处可能和存储的数字冲突，注意区分

        }
        int ret=rear.val;
        if(front==rear){
            front=null;
            rear=null;
            usedSize--;
            return ret;
        }
        rear=rear.prev;
        rear.next=null;
        usedSize--;
        return ret;
    }
    public int  peek(){
        if(front==null){
            return -1;
        }
        return front.val;
        //因为是头插法，后进入的在顶部

    }
    public int getUsedSize(){
        return usedSize;
    }
    public boolean isEmpty(){
        return usedSize==0;
        //这里直接用usedSize与0作比较得到的boolea类型的值直接返回，
    }
    //数组实现队列呢》？
}
